<?php

  session_start();
  include "config.php";
  include "ALproduct.php";

  if(isset($_SESSION["user"]))
  {
    include "$header";
    include "$body";
?>

<div style="position:absolute; top:0px; left:1px; border:0;">
  <span class="page">Enquiry About Products:Search</span>
</div>

<?php
  
    include "$H_eap";

    if(isset($_POST["search"]))
    {
      $description = ltrim($_POST["description"]);
      $dep = ltrim($_POST["department"]);
      $brand = ltrim($_POST["brand"]);
      $size = ltrim($_POST["size"]);
      $colour = ltrim($_POST["colour"]);
      $price1 = ltrim($_POST["price1"]);
      $price2 = ltrim($_POST["price2"]);
      if(validateProductDetails($description, $dep, $brand, $size, $colour, $price1, $price2) == false)
      {
        showForm();
        echo "<SCRIPT language='Javascript'>\n";
        echo "  enquiryProduct.description.value='" . $description . "';\n";
        echo "  enquiryProduct.department.value='" . $dep . "';\n";
        echo "  enquiryProduct.brand.value='" . $brand . "';\n";
        echo "  enquiryProduct.size.value='" . $size . "';\n";
        echo "  enquiryProduct.colour.value='" . $colour . "';\n";
        echo "  enquiryProduct.price1.value='" . $price1 . "';\n";
        echo "  enquiryProduct.price2.value='" . $price2 . "';\n";
        echo "</SCRIPT>";
      }
      else
      {
        $_SESSION["eap_description"] = $description;
        $_SESSION["eap_department"] = $dep;
        $_SESSION["eap_brand"] = $brand;
        $_SESSION["eap_size"] = $size;
        $_SESSION["eap_colour"] = $colour;
        $_SESSION["eap_price1"] = $price1;
        $_SESSION["eap_price2"] = $price2;
        $_SESSION["eap_1"] = getSearchedDetails($description, $dep, $brand, $size, $colour, $price1, $price2);
        $_SESSION["eap_2"] = getRelatedDetails($description, $dep, $brand, $size, $colour, $price1, $price2);
        echo "<SCRIPT language='Javascript'>";
        echo "  window.location.href = 'enquiryAboutProducts_1searchResults.php';";
        echo "</SCRIPT>";
      }
    }
	else
    {
      showForm();
    }
    include "$footer";
  }
  else
  {
    session_destroy();
    echo "<SCRIPT language='Javascript'>";
    echo "  parent.window.location.href = 'index.php';";
    echo "</SCRIPT>";
  }

  function showForm()
  {

?>

<font color="red">*</font> = mandatory field

<p>

<FORM name="enquiryProduct" action="" method="post">

<TABLE class="enquiryAboutProducts" cellpadding="5" cellspacing="5">
  <TR>
    <TD class="eapField">
      Product description<font color="red">*</font>
    </TD>
    <TD class="eapDetails">
      <input type="text" class="enquiryAboutProducts" name="description" style="width:200px" />
    </TD>
  </TR>
  <TR>
    <TD class="eapField">
      Product Department<font color="red">*</font>
    </TD>
    <TD class="eapDetails">
      <select class="enquiryAboutProducts" name="department" style="width:200px" />
        <option value="0">Select:</option>

<?php

  $dep = findAllDepartments();

  for($i=0; $i < sizeof($dep); $i++)
  {

?>

        <option value="<?php echo $dep[$i]; ?>"><?php echo $dep[$i]; ?></option>

<?php

  }

?>

      </select>
    </TD>
  </TR>
  <TR>
    <TD class="eapField">
      Brand Name
    </TD>
    <TD class="eapDetails">
      <input type="text" class="enquiryAboutProducts" name="brand" style="width:200px" />
    </TD>
  </TR>
  <TR>
    <TD class="eapField">
      Size
    </TD>
    <TD class="eapDetails">
      <input type="text" class="enquiryAboutProducts" name="size" style="width:50px" />
    </TD>
  </TR>
  <TR>
    <TD class="eapField">
      Colour
    </TD>
    <TD class="eapDetails">
      <input type="text" class="enquiryAboutProducts" name="colour" style="width:200px" />
    </TD>
  </TR>
  <TR>
    <TD class="eapField">
      Price $
    </TD>
    <TD class="eapDetails">
      <input type="text" class="enquiryAboutProducts" name="price1" style="text-align:right; width:60px" /> . <input type="text" class="enquiryAboutProducts" name="price2" style="width:20px" />
    </TD>
  </TR>
</TABLE>

<p>

<input class="submit_off" type="submit" value="Search" name="search" onmouseover="className='submit_on'" onmouseout="className='submit_off'" />

</FORM>

</BODY>

<?php

  }
  
?>